package com.jiang.smartdangjian.tool;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public abstract class MyAdapter<E> extends RecyclerView.Adapter<MyAdapter.VH> {
    Context context;
    int lay;
    public List<E> list;

    public MyAdapter(Context context, int lay, List<E> list) {
        this.context = context;
        this.lay = lay;
        this.list = list;
    }

    @NonNull
    @Override
    public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new VH(LayoutInflater.from(context).inflate(lay, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull VH holder, int position) {
        init(holder.root, position);
    }

    public abstract void init(View root, int position);

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    static class VH extends RecyclerView.ViewHolder {
        View root;

        public VH(@NonNull View itemView) {
            super(itemView);
            root = itemView;
        }
    }
}
